package Products;

import static org.mockito.Mockito.mock;
import junit.framework.TestCase;

import org.joda.time.DateTime;
import org.junit.Test;

import Exceptions.HistoricalInformationException;
import Magnitudes.Money;

public class HistoricalMapDateMoneyTest extends TestCase {
	
	HistoricalMapDateMoney historicalMapDateMoney = new HistoricalMapDateMoney();
	Exception exception;
	DateTime today = DateTime.now();
	DateTime yesterday = today.minusDays(1);
	Money tenPesos = mock(Money.class);

	@Test
	public void testGivenAnEmptyHistoricalMapDateMoneyWhenAskedForPriceAtSomeDateShouldRaiseHisoricalInformationException(){
		
		try {
			historicalMapDateMoney.priceAt(today);
		} catch (HistoricalInformationException historicalInformationException) {
			exception = historicalInformationException;
		}		
		assertNotNull(exception);
		assertTrue(exception.getMessage().contains("Historical information not available"));
	}
	
	
	@Test
	public void testGivenAnHistoricalMapDateMoneyWhenAskedForPriceNotAvailableAtSomeDateShouldRaiseHisoricalInformationException(){
		historicalMapDateMoney.updatePriceTo(tenPesos);		
		try {
			@SuppressWarnings("unused")
			Money mm = historicalMapDateMoney.priceAt(yesterday);
		} catch (HistoricalInformationException historicalInformationException) {
			exception = historicalInformationException;
		}		
		assertNotNull(exception);
		assertTrue(exception.getMessage().contains("Historical information not available"));
	}
	
	
	@Test
	public void testGivenAnHistoricalMapDateMoneyWhenAskedForPriceShouldReturnThePriceAtThatDay(){
		
		historicalMapDateMoney.updatePriceTo(tenPesos);
		try {
			assertEquals(tenPesos, historicalMapDateMoney.priceAt(today));
		} catch (HistoricalInformationException e) {			
			e.printStackTrace();
		}
	}
	
	
	
}
